package com.dqhl.business.activity;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.business.Base.BaseActivity;
import com.dqhl.business.R;
import com.dqhl.business.adapter.PromotionAllPagerAdapter;

/**
 * description: 整单促销列表
 * autour: guanluocang
 * date: 2016/11/9 13:10 
*/
public class PromotionAllRecordActivity extends BaseActivity implements View.OnClickListener {

    private ImageView iv_goodsGoBack;
    private TextView tv_goodsTopTitle;
    private TextView tv_topRight;
    private ImageView iv_release;
    private ImageView iv_unRelease;
    private ViewPager vp_all;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_promotion_all_record);
        initView();
    }

    private void initView() {
        iv_goodsGoBack = (ImageView) findViewById(R.id.iv_goodsGoBack);
        tv_goodsTopTitle = (TextView) findViewById(R.id.tv_goodsTopTitle);
        tv_topRight = (TextView) findViewById(R.id.tv_topRight);
        vp_all = (ViewPager) findViewById(R.id.vp_all);
        tv_topRight.setVisibility(View.VISIBLE);
        iv_release = (ImageView) findViewById(R.id.iv_release);
        iv_unRelease = (ImageView) findViewById(R.id.iv_unRelease);
        iv_unRelease.setOnClickListener(this);
        iv_release.setOnClickListener(this);
        tv_topRight.setText("添加促销商品");
        tv_topRight.setOnClickListener(this);
        tv_goodsTopTitle.setText("整单促销列表");
        iv_goodsGoBack.setOnClickListener(this);

        vp_all.setAdapter(new PromotionAllPagerAdapter(this.getSupportFragmentManager()));
        vp_all.setCurrentItem(0, true);
        vp_all.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        iv_release.setImageResource(R.drawable.ic_releasepressed);
                        iv_unRelease.setImageResource(R.drawable.ic_unrelease);
                        break;
                    case 1:
                        iv_release.setImageResource(R.drawable.ic_release);
                        iv_unRelease.setImageResource(R.drawable.ic_unreleasepressed);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.tv_topRight:
                overlay(AddPromotionAllActivity.class);
                break;
            case R.id.iv_goodsGoBack:
                finish();
                break;
            case R.id.iv_unRelease:
                vp_all.setCurrentItem(1,true);
                break;
            case R.id.iv_release:
                vp_all.setCurrentItem(0,true);
                break;
        }
    }
}
